﻿<?xml version="1.0" encoding="utf-8" ?>
<entityInfo>
    <aliases>
      <alias id="person">
        SELECT PersonId,FirstName,LastName,Age,Sex FROM Persons
      </alias>
    </aliases>
  
    <sqlStatements>
        <changeStatement id="create" parameterMap="insertMap">
            <command>
                INSERT INTO Persons (FirstName,LastName,Age,Sex) VALUES (@firstname,@lastname,@age,@sex)
            </command>
        </changeStatement>
        <changeStatement id="update" parameterMap="updateMap">
            <command>
                UPDATE Persons SET FirstName=@firstname, LastName=@lastname, Age=@age WHERE PersonId=@id
            </command>
        </changeStatement>
        <changeStatement id="delete" parameterMap="idMap">
            <command>
                DELETE FROM Persons WHERE PersonId=@id
            </command>
        </changeStatement>
        <selectStatement id="bysex" resultMap="personMap" parameterMap="sexMap">
            <command>{person} WHERE Sex=@sex</command>
        </selectStatement>
        <selectStatement id="all" resultMap="personMap">
          <command>{person}</command>
        </selectStatement>
        <singleSelectStatement id="byid" resultMap="personMap" parameterMap="idMap">
            <command>{person} WHERE PersonId=@id</command>
        </singleSelectStatement>
        <storedProcedure id="createPersons" name="CreatePerson" parameterMap="insertMap" />
    </sqlStatements>

    <maps>
        <resultMap id="personMap">
            <fields>
                <field property="Id" column="PersonId" />
                <field property="FirstName" column="FirstName" />
                <field property="LastName" column="LastName" />
                <field property="Age" column="Age" />
                <field property="Sex" column="Sex" />
                <complexField property="Address" extStatement="bypersonid" />
            </fields>
        </resultMap>
        <parameterMap id="insertMap">
            <params>
                <param name="firstname" property="FirstName" />
                <param name="lastname" property="LastName" />
                <param name="age" property="Age" />
                <param name="sex" property="Sex" value="m" />
            </params>
        </parameterMap>
        <parameterMap id="updateMap">
            <params>
                <param name="id" property="Id" />
                <param name="firstname" property="FirstName" />
                <param name="lastname" property="LastName" />
                <param name="age" property="Age" />
            </params>
        </parameterMap>
        <parameterMap id="idMap">
            <params>
                <param name="id" property="Id" />
            </params>
        </parameterMap>
        <parameterMap id="sexMap">
          <params>
              <param name="sex" property="Sex" />
          </params>
        </parameterMap>
    </maps>

</entityInfo>
